﻿using System.Buffers.Text;

namespace Mafool.Core.Test;

[TestClass]
public class AllTest
{
    [TestMethod]
    public void GuidTest()
    {
        try
        {
            for (int i = 50; i > 0; i--) Console.WriteLine(Util.Guid());
        }
        catch (Exception e)
        {
            Assert.Fail(e.Message);
        }
    }

    [TestMethod]
    public void BytesConvert()
    {
        var s = "Hello World".Bytes();
        Assert.AreEqual(s.String(), "Hello World");

        byte[] byteArray = { 72, 101, 108, 108, 111 };
        Assert.AreEqual(byteArray.String(), "Hello");
    }


    [TestMethod]
    public void Md5Test()
    {
        Console.WriteLine("Hello".Md5());
        Console.WriteLine("Dotnet".Md5());

        Console.WriteLine();
        Console.WriteLine("Hello".Sha256());
        Console.WriteLine("Hello".Sha256("X2"));
        Console.WriteLine("Hello".Sha256("D"));

        Console.WriteLine();
        var s = "你好，世界🌍".Base64Encode();
        Console.WriteLine(s);
        Console.WriteLine(s.Base64Decode());
    }

    public record User
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Email { get; set; }
    }
    
    [TestMethod]
    public void JsonTest()
    {
        var user = new User
        {
            Id = 10001,
            Name = "Bob",
            Email = "Bob@gmail.com"
        };

        var userStr = user.Json();
        Console.WriteLine(userStr);
        Console.WriteLine(user.JsonPretty());

        var u = userStr.Object<User>();
        Console.WriteLine($"{u.Id}, {u.Name}, {u.Email}");
    }

    [TestMethod]
    public void TimeTest()
    {
        Console.WriteLine(DateTime.UnixEpoch);
    }

}